home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / rlib / triu < prev    next >
Text File  |  1994-09-23  |  815b  |  42 lines

  1. //-------------------------------------------------------------------//
  2.  
  3. //  Syntax:    triu ( A )
  4. //        triu ( A , K )
  5.  
  6. //  Description:
  7.  
  8. //  triu(x) returns the upper triangular part of A.
  9.  
  10. //  tril(x; k) returns the elements on and above the k-th diagonal of
  11. //  A. 
  12.  
  13. //  K = 0: main diagonal
  14. //  K > 0: above the main diag.
  15. //  K < 0: below the main diag.
  16.  
  17. //  See Also: tril
  18. //-------------------------------------------------------------------//
  19.  
  20. triu = function(x, k) 
  21. {
  22.   if (!exist (k)) { k = 0; }
  23.   nr = x.nr; nc = x.nc;
  24.  
  25.   if(k > 0) 
  26.   { 
  27.     if (k > (nc - 1)) { error ("triu: invalid value for k"); }
  28.   else
  29.     if (abs (k) > (nr - 1)) { error ("triu: invalid value for k"); }
  30.   }
  31.  
  32.   y = zeros(nr, nc);
  33.  
  34.   for(j in max( [1,1+k] ):nc) 
  35.   {
  36.     i = 1:min( [nr, j-k] );
  37.     y[i;j] = x[i;j];
  38.   }
  39.  
  40.   return y;
  41. };
  42.